package nature.nano.util.accepter.schema;

import nature.nano.component.PrimaryPipe;
import nature.nano.component.Strings;
import nature.nano.iface.Props;
import nature.nano.iface.enumer.EnumStringPairCallback;

public class SchemaDetector extends PrimaryPipe {

	private SchemaDetectorHelper head;
	private SchemaDetectorHelper current;
	
	public SchemaDetector() {
		props(Strings.output);
		head = new SchemaDetectorHelper();
		current = head;
	}

	@Override
	public void anBegin(String type, Props props) {
		current = current.addChild(type);
		props.enumProp(
			new EnumStringPairCallback() {
				public void onRead(String key, String value) {
					current.onProp(key, value);
				}				
			});
	}
	
	@Override
	public void anEnd(String type) {
		current = current.getParent();
		if (current == head) {
			head.flush(slot(Strings.output));
		}
	}

	@Override
	public void anContent(String content) {
		current.onContent(content.length());
	}
	
}
